package com.share.cloudStorage.files.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.share.cloudStorage.files.model.Files;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface FilesDao extends BaseMapper<Files> {


    void recycleByIds(@Param("intFileIds") List<Integer> intFileIds,@Param("status") int status);
    //通过递归删除
    @Update("<script>"
            + "WITH RECURSIVE file_tree AS ("
            + "   SELECT file_id FROM files WHERE file_id IN "
            + "   <foreach item='id' collection='intFileIds' open='(' separator=',' close=')'>"
            + "       #{id}"
            + "   </foreach>"
            + "   UNION ALL "
            + "   SELECT f.file_id FROM files f "
            + "   INNER JOIN file_tree ft ON f.parent_id = ft.file_id"
            + ") "
            + "UPDATE files "
            + "SET is_delete= #{status} "
            + "WHERE file_id IN (SELECT file_id FROM file_tree)"
            + "</script>")
    void deleteById(@Param("intFileIds") List<Integer> intFileIds,@Param("status") int status);


    List<Files> searchByFileId(Integer fileId);

    List<Integer> searchFileIdAndParentId(List<Integer> fileIdList);
}

